package logic

import (
	"context"
	"youngwind-first/demo/internal/svc"
	"youngwind-first/demo/internal/types"
	"youngwind-first/demo/model/gorm_model"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUpdateLogic) UserUpdate(req *types.User) (resp *types.Response, err error) {

	ub := &gorm_model.User{}
	ub.Id = req.Id
	ub.Name = req.Name
	ub.Age = req.Age
	err = l.svcCtx.DbEngin.Save(ub).Error
	if err != nil {
		return nil, err
	}
	resp = new(types.Response)
	resp.Message = "ok"
	return
}
